//
//  ReagentDetailViewController.m
//  autostainer
//
//  Created by lurenjia on 2017/5/24.
//  Copyright © 2017年 walker. All rights reserved.
//

#import "ReagentDetailViewController.h"

@interface ReagentDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSArray *dataArray;
@property (copy, nonatomic) NSString *reactionStr;
@end

@implementation ReagentDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"ModelFile" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
    NSArray *arr = dict[@"data"];
    NSMutableArray<DataModel *> *arrM = [NSMutableArray array];
    for (NSDictionary *dict in arr) {
        DataModel *model = [[DataModel alloc]initWithDict:dict];
        [arrM addObject:model];
    }
    self.dataArray = arrM[_experimentType].experimentDetails;
    NSString *str = arrM[_experimentType].experimentName;
//    self.navigationController.navigationItem.title = str;
    [self.navigationItem setTitle:str];
    
    if ([str isEqualToString:@"DNA复染"]) {
        _reactionStr = @"FE030100000C04010103840402030384040302003C0404040E10040502003C0406060FB4040702003C04080700780409070078040A010078040B010078040C09012C3DFF";
    }
    else if ([str isEqualToString:@"HE染色"]) {
        _reactionStr = @"FE030100000D01010103840102030384010302003C0104040E10010502003C0106060FB4010702003C0108070078010905012C010A070078010B070078010C010078010D0100726FF";
    }
    else if ([str isEqualToString:@"巴氏染色"]) {
        _reactionStr = @"FE030100000D02010100780202020078020306012C0204020078020504000302060202580207030708020802003C0209070078020A070078020B010078020C010078020D0900B40EFF";
    }
    else if ([str isEqualToString:@"feulgen染色"]) {
        _reactionStr = @"FE03010000110301010078030202007803030601A403040200F00305040258030602025803070700780308010078030903000F030A07003C030B01003C030C0501A4030D070078030E070078030F010078031001007803110900B454FF";
    }
    else if ([str isEqualToString:@"feulgen复染"]) {
        _reactionStr = @"FE030100001305010103840502030384050302003C0504040E10050502003C0506060D5C050702003C05080700780509070078050A010078050B010078050C09012C050D070078050E05012C050F07007805100700780511010078051201007805130900B42BFF";
    }
    
}
- (IBAction)start:(UIBarButtonItem *)sender {
    ReactionViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ReactionViewController"];
    vc.dataArray = self.dataArray;
    vc.ReactionStr = _reactionStr;
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell;
    if (indexPath.row == 0) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"titleCell" forIndexPath:indexPath];
    } else {
        cell = [tableView dequeueReusableCellWithIdentifier:@"DetailCell" forIndexPath:indexPath];
        UILabel *nameLabel = [cell.contentView viewWithTag:1];
        UILabel *timeLabel = [cell.contentView viewWithTag:2];
        UILabel *noteLabel = [cell.contentView viewWithTag:3];
        
        ExperimentModel *model = self.dataArray[indexPath.row];
        nameLabel.text = model.name;
        if ([model.time rangeOfString:@"S"].location == NSNotFound) {
            timeLabel.text = [NSString stringWithFormat:@"%@分钟",model.time];
        }
        else {
            timeLabel.text = [NSString stringWithFormat:@"%@分钟",model.time];
        }
        if (![model.note isEqualToString:@"0"]) {
            noteLabel.text = [NSString stringWithFormat:@"%@℃",model.note];
        }else {
            noteLabel.text = @"";
        }
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1;
}



@end
